package edu.xidian.bdilab.jrbigdata.controller.enterprise;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.FinancialProduct;
import edu.xidian.bdilab.jrbigdata.service.enterprise.productCheck.ProductCheckService;
import edu.xidian.bdilab.jrbigdata.util.ConvertString;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ProductCheckController
 * @Description TODO
 * @Author tuantuan
 * @Date 2019/3/30 下午9:43
 * @Version 1.0
 * @Attention Copyright (C), 2004-2019, BDILab, XiDian University
 **/
@RestController
@Api(tags = {"productCheck-查看金融产品功能"})
public class ProductCheckController {
    @Autowired
    ProductCheckService productCheckService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "institutionType", value = "机构类型"),
            @ApiImplicitParam(name = "loanLimit", value = "贷款额度"),
            @ApiImplicitParam(name = "loanPeriod", value = "贷款期限"),
            @ApiImplicitParam(name = "guaranteeMode", value = "担保方式"),
            @ApiImplicitParam(name = "internetLoanType", value = "网贷直联"),
            @ApiImplicitParam(name = "productProperties", value = "政策性产品")
    })
    @RequestMapping(value = "enterprise/productCheck/{socialCode}", method = RequestMethod.POST)
    public ResponseResult productCheck(@RequestParam(required = false) String institutionType,
                                       @RequestParam(required = false) String loanLimit,
                                       @RequestParam(required = false) String loanPeriod,
                                       @RequestParam(required = false) String guaranteeMode,
                                       @RequestParam(required = false) String internetLoanType,
                                       @RequestParam(required = false) String productProperties,
                                        @PathVariable String socialCode
//                                       HttpSession httpSession
    ){

//        System.out.println(httpSession);

        ResponseResult responseResult = new ResponseResult();

        ConvertString convertString = new ConvertString();

        List<FinancialProduct> financialProducts;

        financialProducts = productCheckService.checkProduct(
                convertString.StringToInt(institutionType),
                convertString.StringToInt(loanLimit),
                convertString.StringToInt(loanPeriod),
                convertString.StringToInt(guaranteeMode),
                convertString.StringToInt(internetLoanType),
                convertString.StringToInt(productProperties),
                socialCode);

        if (financialProducts.isEmpty() == true){
            responseResult.setSuccess(false);
            responseResult.setCode(EnterpriseCode.PRODUCT_CHECK_FAIL.getCode());
            responseResult.setMessage(EnterpriseCode.PRODUCT_CHECK_FAIL.getMessage());
            return responseResult;
        }else {
            responseResult.setData(financialProducts);
            responseResult.setSuccess(true);
            responseResult.setCode(EnterpriseCode.PRODUCT_CHECK_SUCCESS.getCode());
            responseResult.setMessage(EnterpriseCode.PRODUCT_CHECK_SUCCESS.getMessage());
        }

        return responseResult;
    }

    /**
     * 发送短信验证码
     * @param fkBankId
     * @param socialCode
     * @return
     */
    @RequestMapping(value = "enterprise/sendMsg", method = RequestMethod.POST)
    public ResponseResult productCheck(@RequestParam(required = false) String fkBankId,
                                       @RequestParam(required = false) String socialCode){
        ResponseResult responseResult = productCheckService.sendAliyunMsg(fkBankId, socialCode);
        return responseResult;
    }
}
